package com.null_pointer.project2.bean.vo;



import lombok.Data;

import java.util.List;

@Data
public class BaseRespVo <T> {
    private String errmsg;
    private int errno;
    private T data;

    // 返回一个对象的vo
    public static <T> BaseRespVo<T> ok (T data) {
        BaseRespVo<T> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("success");
        baseRespVo.setErrno(0);
        baseRespVo.setData(data);

        return baseRespVo;
    }

    // 返回集合对象的vo
    public static BaseRespVo<PageVo> okList (List list) {
        BaseRespVo<PageVo> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("success");
        baseRespVo.setErrno(0);

        PageVo page = PageVo.toPage(list);
        baseRespVo.setData(page);

        return baseRespVo;
    }

    // 用户名或密码错误的vo
    public static BaseRespVo wrongAuth() {
        BaseRespVo baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("Incorrect username or password");
        baseRespVo.setErrno(605);
        return baseRespVo;
    }

    // 未登录的vo
    public static BaseRespVo unLogin() {
        BaseRespVo baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("Not logged in");
        baseRespVo.setErrno(501);
        return baseRespVo;
    }

    // 非法参数的vo
    public static BaseRespVo illegalParam() {
        BaseRespVo baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("Please provide the correct parameters");
        baseRespVo.setErrno(400);
        return baseRespVo;
    }

    public static BaseRespVo ok(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }
}
